<!DOCTYPE html>
<html xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>系统设置
            <small>菜单管理</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>系统设置</el-breadcrumb-item>
            <el-breadcrumb-item>菜单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container" @keyup.enter="search()">
                <el-input placeholder="菜单名称/角色名称" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" ></el-input>
                <el-button @click="search()" class="dalfBut">查询</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <!--序号 角色名 菜单名称 路径 图标  描述-->
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <!--<el-table-column prop="roleName" label="角色名称" align="center"></el-table-column>-->
                <el-table-column prop="name" label="菜单名称" align="center"></el-table-column>
                <el-table-column prop="filepath" label="路径" align="center"></el-table-column>
                <el-table-column prop="priority" label="优先级" align="center"></el-table-column>
                <el-table-column prop="icon" label="图标" align="center">
                    <template slot-scope="scope">
                        <i class="fa" :class="scope.row.icon"></i>
                    </template>
                </el-table-column>
                <el-table-column prop="description" label="描述" align="center"></el-table-column>
                <el-table-column label="操作" align="center" width="300">
                    <template slot-scope="scope">
                        <el-button type="info" size="mini" @click="handleDetail(scope.row)">详细</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增角色菜单" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="11">
                                <el-form-item label="角色名称" prop="roleName">
                                    <el-input v-model="formData.roleName" placeholder="roleName"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="11">
                                <el-form-item label="菜单名" prop="name">
                                    <el-input v-model="formData.name" placeholder="XXX/YYY"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>


            <!-- 编辑详细弹层 -->
            <div class="add-form">
                <el-dialog title="查看权限角色" :visible.sync="dialogFormVisible4Detail">
                        <el-table
                                ref="multipleTable"
                                :data="tableData"
                                tooltip-effect="dark"
                                style="width: 100%"
                                @selection-change="handleSelectionChange">
                            <el-table-column
                                    type="selection"
                                    width="55">
                            </el-table-column>
                            <el-table-column
                                    prop="name"
                                    label="角色名称"
                                    width="150">
                                <template slot-scope="scope">{{ scope.row.name }}</template>
                            </el-table-column>
                            <el-table-column
                                    prop="description"
                                    label="角色说明"
                                    width="400">
                            </el-table-column>
                        </el-table>
                    <div style="margin-top: 20px;text-align:right">
                        <el-button @click="dialogFormVisible4Detail = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: {},//总记录数
                queryString: null//查询条件
            },
            menuData:[],
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            tableData: [],//详细数据
            multipleSelection: [],//选中role数据
            menuId:"",//编辑菜单id
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Detail: false,
            rules: {//校验规则
                name: [{required: true, message: '菜单名称为必填项', trigger: 'blur'}],
                roleName: [{required: true, message: '角色名称为必填项', trigger: 'blur'}]
            },
            icons:[
                {
                    label:"用户1",
                    value:"fa fa-user-md",
                },
                {
                    label:"用户2",
                    value:"fa fa-user-circle",
                },
                {
                    label:"电话",
                    value:"fa fa-tty",
                },
                {
                    label:"监听器",
                    value:"fa fa-stethoscope",
                },
                {
                    label:"心",
                    value:"fa fa-heartbeat",
                },
                {
                    label:"星",
                    value:"el-icon-star-on",
                },
                {
                    label:"多标签",
                    value:"fa fa-tags",
                },
                {
                    label:"钻石",
                    value:"fa fa-diamond",
                },
                {
                    label:"图表",
                    value:"fa fa-bar-chart",
                },
                {
                    label:"多用户",
                    value:"fa fa-users",
                },
                {
                    label:"上传",
                    value:"el-icon-upload",
                },
                {
                    label:"设置",
                    value:"el-icon-setting",
                },
                {
                    label:"手机",
                    value:"el-icon-mobile-phone",
                },
                {
                    label:"电脑",
                    value:"fa fa-television",
                },
                {
                    label:"位置",
                    value:"el-icon-location",
                },
                {
                    label:"分享",
                    value:"el-icon-share",
                },
                {
                    label:"回收",
                    value:"el-icon-delete",
                },
                {
                    label:"信息",
                    value:"el-icon-news",
                },
                {
                    label:"消息",
                    value:"el-icon-message",
                },
                {
                    label:"消息2",
                    value:"fa fa-commenting-o",
                },
                {
                    label:"chrome",
                    value:"fa fa-chrome",
                },
                {
                    label:"QQ",
                    value:"fa fa-qq",
                },
                {
                    label:"微信",
                    value:"fa fa-weixin",
                },
                {
                    label:"apple",
                    value:"fa fa-apple",
                },
            ]
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //没有操作权限弹出框
            showMessage(r) {
                if (r == 'Error: Request failed with status code 403') {
                    //权限不足
                    this.$message.error('无访问权限');
                    return;
                } else {
                    this.$message.error('未知错误');
                    return;
                }
            },

            handleDetail(row) {
                this.dialogFormVisible4Detail = true;

                axios.get("/menu/findRoleByMenuId.do",{params:{"id":row.id}}).then((res)=>{
                    if(res.data.flag){
                        this.menuId=row.id;
                        this.tableData=res.data.data.tableData;
                        this.tableData.forEach((t)=>{
                            res.data.data.multipleSelection.forEach((m)=>{
                                if(t.id==m.id){
                                    this.toggleSelection([t]);
                                }
                            })
                        })
                    }else{
                        this.$message(res.data.message);
                    }
                }).catch((res) => {
                    this.showMessage(res);
                });
            },
            handleEdit(){
                axios.post(`/menu/modifyMenuRole.do?menuId=${this.menuId}`,this.multipleSelection).then((res)=>{
                    this.$message(res.data.message);
                    if(res.data.flag){
                        this.dialogFormVisible4Detail = false;
                    }
                })
            },
            toggleSelection(rows) {
                if (rows) {
                    this.$nextTick(function () {
                        rows.forEach(row => {
                            this.$refs.multipleTable.toggleRowSelection(row);
                        });
                    })
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            search() {
                this.pagination.currentPage = 1;
                this.findPage();
            },
            //分页查询
            findPage() {
                axios.post("/menu/findByPage.do", {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                }).then((res) => {
                    this.dataList = res.data.rows;
                    this.pagination.total = res.data.total;
                }).catch((res) => {
                    this.showMessage(res);
                });
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                this.dialogFormVisible = true;
                this.resetForm();
                axios.post("/menu/findParentMenu").then((res) => {
                    this.menuData = res.data.data;
                });
            },

            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
        }
    })
</script>
</html>